package cn.money.transport.mq;

import cn.monkey.transport.core.ExchangeContext;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class MapExchangeContext implements ExchangeContext {
    private final Map<String, Object> attributeMap;

    public MapExchangeContext(Map<String, Object> attributeMap) {
        this.attributeMap = attributeMap;
    }

    public MapExchangeContext() {
        this(new ConcurrentHashMap<>());
    }

    @Override
    @SuppressWarnings("unchecked")
    public <T> T setAttribute(String key, T val) {
        return (T) this.attributeMap.put(key, val);
    }

    @Override
    @SuppressWarnings("unchecked")
    public <T> T getAttribute(String key) {
        return (T) this.attributeMap.get(key);
    }
}
